﻿using Coldairarrow.Business.BaseConfig;
using Coldairarrow.Entity.BaseConfig;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.BaseConfig
{
    [Route("/BaseConfig/[controller]/[action]")]
    public class Base_SysConfigController : BaseApiController
    {
        #region DI

        public Base_SysConfigController(IBase_SysConfigBusiness base_SysConfigBus)
        {
            _base_SysConfigBus = base_SysConfigBus;
        }

        IBase_SysConfigBusiness _base_SysConfigBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_SysConfig>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _base_SysConfigBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_SysConfig> GetTheData(IdInputDTO input)
        {
            return await _base_SysConfigBus.GetTheDataAsync(input.Id);
        }

        /// <summary>
        /// 后台——获取系统配置数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ConfigTypeDTO>> GetTheConfigData()
        {
            return await _base_SysConfigBus.GetConfigList();
        }

        /// <summary>
        /// 后台——保存配置数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task SetTheConfigData(List<ConfigTypeDTO> input)
        {
             await _base_SysConfigBus.SetConfig(input);
        }
        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_SysConfig data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _base_SysConfigBus.AddDataAsync(data);
            }
            else
            {
                await _base_SysConfigBus.UpdateDataAsync(data);
            }
        }


        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _base_SysConfigBus.DeleteDataAsync(ids);
        }
         #endregion
    }
}